home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 64
/
Volume 64 - JOGO DISK .iso
/
Games
/
the_best_every_day.swf
/
scripts
/
__Packages
/
ObstacleGenerator.as
< prev
next >
Wrap
Text File
|
2008-04-10
|
5KB
|
156 lines
class ObstacleGenerator
{
var ARRAY_OBSTACLE_TYPES = new Array("Bubbles","Bubbles","Bubbles","Banana","Banana","Banana","Gary","Gary");
function ObstacleGenerator(l_oTimeGeneratorSpeed)
{
this.setObject();
this.__set__time(l_oTimeGeneratorSpeed);
}
function update()
{
this.oTime.update();
if(this.oTime.__get__timeOut())
{
var _loc6_ = 0;
while(_loc6_ < 5)
{
var _loc3_ = undefined;
var _loc2_ = undefined;
var _loc4_ = 0;
do
{
_loc3_ = Math.floor(Math.random() * this.ARRAY_OBSTACLE_TYPES.length);
_loc2_ = this.ARRAY_OBSTACLE_TYPES[_loc3_];
_loc4_ = _loc4_ + 1;
if(_loc4_ > 25)
{
break;
}
}
while(_loc4_ < 4 && (this.oObstacles[_loc2_].length == 0 || this.oObstacles[_loc2_].length == 1 && this.oObstacles[_loc2_][0].getActive()));
if(_loc4_ < 4)
{
var _loc5_ = 0;
do
{
_loc5_ = _loc5_ + 1;
if(_loc5_ > 10)
{
break;
}
_loc3_ = Math.floor(Math.random() * this.oObstacles[_loc2_].length);
}
while(this.oObstacles[_loc2_][_loc3_].getActive());
}
if(this.getDistanceBetween(this.oPatrick.mc,this.oObstacles[_loc2_][_loc3_]) > 350)
{
_loc6_ = 10;
}
_loc6_ = _loc6_ + 1;
}
this.oObstacles[_loc2_][_loc3_].setObstacle();
this.aActiveObstacles.push(this.oObstacles[_loc2_][_loc3_]);
this.reset();
}
this.Collide();
}
function getDistanceBetween(__movie1, __movie2)
{
var _loc1_ = Math.abs(__movie1._x - __movie2._x);
var _loc2_ = Math.abs(__movie1._y - __movie2._y);
return _loc1_ + _loc2_ * 3;
}
function addObstacle(l_mcObstacle, l_sType)
{
this.oObstacles[l_sType].push(l_mcObstacle);
if(l_sType == "Slobber")
{
this.aActiveObstacles.push(l_mcObstacle);
}
}
function removeObstacle(l_mcObstacle)
{
for(var _loc2_ in this.aActiveObstacles)
{
if(l_mcObstacle == this.aActiveObstacles[_loc2_])
{
this.aActiveObstacles.splice(_loc2_,1);
}
}
}
function reset()
{
var _loc4_ = this.oOriginalTime.__get__minutes();
var _loc3_ = this.oOriginalTime.__get__seconds() - Math.floor(_global.Pack.nLevel / 3);
if(_loc3_ < 5)
{
_loc3_ = 5;
}
this.oTime = new sarbakan.utils.Time(_loc4_,_loc3_);
}
function setObject()
{
var _loc2_ = undefined;
this.oObstacles = new Object();
for(_loc2_ in this.ARRAY_OBSTACLE_TYPES)
{
this.oObstacles[this.ARRAY_OBSTACLE_TYPES[_loc2_]] = new Array();
}
this.aActiveObstacles = new Array();
}
function Collide()
{
var _loc2_ = undefined;
this.oPatrick.trap(false);
if(this.oPatrick.bActive && this.oPatrick.sState == "Move")
{
for(_loc2_ in this.aActiveObstacles)
{
if(this.oPatrick.mc.mcDetector.hitTest(this.aActiveObstacles[_loc2_]))
{
if(this.aActiveObstacles[_loc2_].getType() != "Gary")
{
this.oPatrick.trap(true,this.aActiveObstacles[_loc2_]);
}
}
}
}
}
function addTime(l_oTime)
{
this.oTime.addTime(l_oTime);
}
function set time(l_oTime)
{
this.oTime = l_oTime;
this.oOriginalTime = new sarbakan.utils.Time(l_oTime.__get__minutes(),l_oTime.__get__seconds());
var _loc3_ = l_oTime.__get__seconds() - Math.floor(_global.Pack.nLevel / 3);
if(_loc3_ < 5)
{
_loc3_ = 5;
}
trace("time between event = " + _loc3_);
}
function set patrick(l_oPatrick)
{
this.oPatrick = l_oPatrick;
}
function garyCollide()
{
var _loc2_ = undefined;
for(_loc2_ in this.aActiveObstacles)
{
if(this.aActiveObstacles[_loc2_].getType() == "Slobber")
{
if(this.oPatrick.mc._parent.gary.mcEdgeDetector.hitTest(this.aActiveObstacles[_loc2_]))
{
return false;
}
}
}
return true;
}
}